package com.zx.controller;

import com.zx.bean.Firm;
import com.zx.dto.AjaxJson;
import com.zx.service.FirmService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class FirmController {
    @Autowired
    private FirmService firmService;

   /* @GetMapping("/toindex")
    public String toindex(){
        return "index";
    }*/

    /*//查询所有页面
    @GetMapping("/findFirmList")
    public String findFirmList(Firm firm){
        List<Firm> firmList=firmService.findAllFirm();
        //传进去的是一个键值对
        firm.addAttribute("firmList",firmList);//传进前端的东西
        //返回值==html文件名
        return "findFirmList";

    }*/

    /*//跳转到添加页面
    @GetMapping("/toaddFirm")
    public String toaddFirm(){
        //返回值为文件名
        return "addFirm";
    }*/

    //定义一个添加的接口
    @PostMapping("/addFirm")
    public String addFirm(Firm firm){
        firmService.addFirm(firm);
        return "addFirm";
    }

    //定义一个删除接口
    @PostMapping("/delFirm")
    public String delFirm(int id){
        firmService.delFirm(id);
        return "delFirm";
    }

    //定义一个修改的接口
    @PostMapping("/updateFirm")
    public String updateFirm(int id){
        firmService.updateFirm(id);
        return "updateFirm";
    }

    //定义一个查询单个的接口
    @PostMapping("/findOneFirm")
    @ResponseBody
    public AjaxJson findOneFirm(int id){
        AjaxJson ajaxJson = new AjaxJson();
        Firm firm = firmService.findOneFirm(id);
        ajaxJson.put("firm",firm);
        return ajaxJson;
    }

  /*  //定义一个查询全部的接口
    @PostMapping("/getAllFirm")
    @ResponseBody
    public AjaxJson getAllFirm(){
        AjaxJson ajaxJson = new AjaxJson();
        firmService.findAllFirm();
        return ajaxJson;
    }*/

    @GetMapping("/getAllFirm")
    @ResponseBody
    public AjaxJson getAllAddress(){
        AjaxJson ajaxJson = new AjaxJson();
        List<Firm> firmList=firmService.findAllFirm();
        ajaxJson.put("firmList",firmList);
        return ajaxJson;
    }
}
